home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / IISCNFG.VB_ / iiscnfg.vbs
Encoding:
Text File  |  2003-02-21  |  35.2 KB  |  922 lines

  1. '
  2. ' Copyright (c) Microsoft Corporation.  All rights reserved.
  3. '
  4. ' VBScript Source File 
  5. '
  6. ' Script Name: IIsCnfg.vbs
  7. '
  8.  
  9. Option Explicit
  10. On Error Resume Next
  11.  
  12. ' Error codes
  13. Const ERR_OK              = 0
  14. Const ERR_GENERAL_FAILURE = 1
  15.  
  16. '''''''''''''''''''''
  17. ' Messages
  18. Const L_ConfImported_Text       = "Configuration imported from %1 in file"
  19. Const L_ConfImportedp2_Text     = "%1 to %2 in the Metabase."
  20. Const L_ConfExported_Text       = "Configuration exported from %1 to file %2."
  21. Const L_MDSaved_Text            = "Metadata successfully flushed to disk."
  22.  
  23. Const L_Error_ErrorMessage                   = "Error &H%1: %2"
  24. Const L_GetComputerObject_ErrorMessage       = "Could not get computer object"
  25. Const L_Import_ErrorMessage                  = "Error while importing configuration."
  26. Const L_Export_ErrorMessage                  = "Error while exporting configuration."
  27. Const L_SaveData_ErrorMessage                = "Error while flushing metabase."
  28. Const L_OnlyOneOper_ErrorMessage             = "Please specify only one operation at a time."
  29. Const L_ScriptHelper_ErrorMessage            = "Could not create an instance of the"
  30. Const L_ScriptHelperp2_ErrorMessage          = "IIsScriptHelper object."
  31. Const L_ChkScpHelperReg_ErrorMessage         = "Please register the Microsoft.IIsScriptHelper"
  32. Const L_ChkScpHelperRegp2_ErrorMessage       = "component."
  33. Const L_CmdLib_ErrorMessage                  = "Could not create an instance of the CmdLib object."
  34. Const L_ChkCmdLibReg_ErrorMessage            = "Please register the Microsoft.CmdLib component."
  35. Const L_WMIConnect_ErrorMessage              = "Could not connect to WMI provider."
  36. Const L_RequiredArgsMissing_ErrorMessage     = "Required arguments are missing."
  37. Const L_FileExpected_ErrorMessage            = "Argument is a folder path while expecting a file"
  38. Const L_FileExpectedp2_ErrorMessage          = "path."
  39. Const L_ParentFolderDoesntExist_ErrorMessage = "Parent folder doesn't exist."
  40. Const L_FileDoesntExist_ErrorMessage         = "Input file doesn't exist."
  41. Const L_FileAlreadyExist_ErrorMessage        = "Export file specified already exists."
  42. Const L_NotEnoughParams_ErrorMessage         = "Not enough parameters."
  43. Const L_InvalidSwitch_ErrorMessage           = "Invalid switch: %1"
  44. Const L_IncorrectPassword_ErrorMessage       = "The password specified is incorrect."
  45. Const L_InvalidXML_ErrorMessage              = "The import file appears to contain invalid XML."
  46. Const L_Admin_ErrorMessage                   = "You cannot run this command because you are not an"
  47. Const L_Adminp2_ErrorMessage                 = "administrator on the server you are trying to configure."
  48. Const L_DriveLetter_Message                  = "Mapping local drive %1 to admin share on server %2"
  49. Const L_Shell_ErrorMessage                   = "Could not create an instance of the WScript.Shell"
  50. Const L_Shellp2_ErrorMessage                 = "object."
  51. Const L_FS_ErrorMessage                      = "Could not create an instance of the"
  52. Const L_FSp2_ErrorMessage                    = "Scripting.FileSystemObject object."
  53. Const L_Network_ErrorMessage                 = "Could not create an instance of the"
  54. Const L_Networkp2_ErrorMessage               = "WScript.Network object."
  55. Const L_BackingUp_Message                    = "Backing up server %1"
  56. Const L_Restoring_Message                    = "Restoring on server %1"
  57. Const L_Backup_ErrorMessage                  = "Failure creating backup."
  58. Const L_BackupComplete_Message               = "Backup complete."
  59. Const L_Restore_ErrorMessage                 = "Failure restoring backup."
  60. Const L_RestoreComplete_Message              = "Restore complete."
  61. Const L_UnMap_Message                        = "Unmapping local drive %1"
  62. Const L_NoDrive_ErrorMessage                 = "No drives available for mapping on local machine."
  63. Const L_Copy_Message                         = "Copying backup files..."
  64. Const L_Copy_ErrorMessage                    = "Error copying files."
  65. Const L_ReturnVal_ErrorMessage               = "Call returned with code %1"
  66. Const L_CopyComplete_Message                 = "Copy operation complete."
  67. '''''''''''''''''''''
  68. ' Help
  69. Const L_Empty_Text     = ""
  70.  
  71. ' General help messages
  72. Const L_SeeHelp_Message         = "Type IIsCnfg /? for help."
  73. Const L_SeeImportHelp_Message   = "Type IIsCnfg /import /? for help."
  74. Const L_SeeExportHelp_Message   = "Type IIsCnfg /export /? for help."
  75.  
  76. Const L_Help_HELP_General01_Text   = "Description: Import and export IIS configuration."
  77. Const L_Help_HELP_General02_Text   = "Syntax: IIsCnfg [/s <server> [/u <username> [/p <password>]]]"
  78. Const L_Help_HELP_General03_Text   = "        /<operation> [arguments]"
  79. Const L_Help_HELP_General04_Text   = "Parameters:"
  80. Const L_Help_HELP_General05_Text   = ""
  81. Const L_Help_HELP_General06_Text   = "Value                   Description"
  82. Const L_Help_HELP_General07_Text   = "/s <server>             Connect to machine <server>."
  83. Const L_Help_HELP_General07p2_Text = "                        [Default: this system]"
  84. Const L_Help_HELP_General08_Text   = "/u <username>           Connect as <domain>\<username> or"
  85. Const L_Help_HELP_General09_Text   = "                        <username>. [Default: current user]"
  86. Const L_Help_HELP_General10_Text   = "/p <password>           Password for the <username> user."
  87. Const L_Help_HELP_General11_Text   = "<operation>             /import     Import configuration from"
  88. Const L_Help_HELP_General11p1_Text = "                                    a configuration file."
  89. Const L_Help_HELP_General12_Text   = "                        /export     Export configuration into"
  90. Const L_Help_HELP_General12p1_Text = "                                    a configuration file."
  91. Const L_Help_HELP_General13_Text   = "                        /copy       Copy configuration from"
  92. Const L_Help_HELP_General14_Text   = "                                    one machine to another."
  93. Const L_Help_HELP_General22_Text   = "For detailed usage:"
  94. Const L_Help_HELP_General23_Text   = "IIsCnfg /import /?"
  95. Const L_Help_HELP_General24_Text   = "IIsCnfg /export /?"
  96. Const L_Help_HELP_General25_Text   = "IIsCnfg /copy /?"
  97. Const L_Help_HELP_General26_Text   = "IIsCnfg /save /?"
  98.  
  99. ' Common help messages
  100. Const L_Help_HELP_Common13_Text   = "/d <DecryptPass>        Specifies the password used to"
  101. Const L_Help_HELP_Common13p1_Text = "                        decrypt encrypted configuration data."
  102. Const L_Help_HELP_Common13p2_Text = "                        [Default: """"]"   
  103. Const L_Help_HELP_Common14_Text   = "/f <File>               Configuration file."
  104. Const L_Help_HELP_Common15_Text   = "/sp <SourcePath>        The full metabase path to start"
  105. Const L_Help_HELP_Common15p1_Text = "                        reading from the configuration file."
  106. Const L_Help_HELP_Common21_Text   = "Examples:"
  107.  
  108. ' Copy help messages
  109. Const L_Help_HELP_Copy1_Text      = "Description:  Copy configuration from a source server to a"
  110. Const L_Help_HELP_Copy1p2_Text    = "              target server."
  111. Const L_Help_HELP_Copy2_Text      = "Syntax: iiscnfg [/s <server> [/u <username> [/p <password>]]]"
  112. Const L_Help_HELP_Copy2p2_Text    = "        /copy  /ts <target server> /tu <target user>"
  113. Const L_Help_HELP_Copy2p3_Text    = "        /tp <target password>"
  114. Const L_Help_HELP_Copy3_Text      = "Parameters:"
  115. Const L_Help_HELP_Copy4_Text      = "Value                   Description"
  116. Const L_Help_HELP_Copy5_Text      = "/s <server>           Connect to machine <server>"
  117. Const L_Help_HELP_Copy5p2_Text    = "                      [Default: this system]"
  118. Const L_Help_HELP_Copy6_Text      = "/u <username>         Connect as <domain>/<username>"
  119. Const L_Help_HELP_Copy7_Text      = "                      or <username> [Default: current user]"
  120. Const L_Help_HELP_Copy8_Text      = "/p <password>         Password for the <username> user"
  121. Const L_Help_HELP_Copy9_Text      = "/ts                   Target server to copy configuration to"
  122. Const L_Help_HELP_Copy10_Text     = "/tu                   Username to use when connecting to the"
  123. Const L_Help_HELP_Copy10p2_Text   = "                      target server"
  124. Const L_Help_HELP_Copy11_Text     = "/tp                   Password to use when connecting to the"
  125. Const L_Help_HELP_Copy11p2_Text   = "                      target server"
  126. Const L_Help_HELP_Copy12_Text     = "Examples:"
  127. Const L_Help_HELP_Copy13_Text     = "iiscnfg.vbs /copy /ts TargetServer /tu Administrator /tp Pk$^("
  128. Const L_Help_HELP_Copy14_Text     = "iiscnfg.vbs /s SourceServer /u Administrator /p Kj30W /copy"
  129. Const L_Help_HELP_Copy14p2_Text   = "            /ts TargetServer /tu Administrator /tp Pk$^j"
  130.  
  131. ' Import help messages
  132. Const L_Help_HELP_Import01_Text   = "Description: Import configuration from a configuration file."
  133. Const L_Help_HELP_Import02_Text   = "Syntax: IIsCnfg [/s <server> [/u <username> [/p <password>]]]"
  134. Const L_Help_HELP_Import02p1_Text = "        /import [/d <DeCryptPass>] /f <File> /sp <SourcePath>"
  135. Const L_Help_HELP_Import02p2_Text = "        /dp <DestPath> [/inherited] [/children] [/merge]"
  136. Const L_Help_HELP_Import16_Text   = "/dp <DestPath>          The metabase path destination for"
  137. Const L_Help_HELP_Import16p1_Text = "                        imported properties.  If the keytype"
  138. Const L_Help_HELP_Import16p2_Text = "                        of the SourcePath and the DestPath do"
  139. Const L_Help_HELP_Import16p3_Text = "                        not match, an error occurs."
  140. Const L_Help_HELP_Import17_Text   = "/inherited              Import inherited settings if set."
  141. Const L_Help_HELP_Import18_Text   = "/children               Import configuration for child nodes."
  142. Const L_Help_HELP_Import19_Text   = "/merge                  Merge imported configuration with"
  143. Const L_Help_HELP_Import19p1_Text = "                        existing configuration."
  144. Const L_Help_HELP_Import22_Text   = "IIsCnfg /import /f c:\config.xml /sp /lm/w3svc/5/Root/401Kapp"
  145. Const L_Help_HELP_Import22p1_Text = "        /dp /lm/w3svc/1/Root/401Kapp"
  146.  
  147. ' Export help messages
  148. Const L_Help_HELP_Export01_Text   = "Description: Export configuration into a configuration file."
  149. Const L_Help_HELP_Export02_Text   = "Syntax: IIsCnfg [/s <server> [/u <username> [/p <password>]]]"
  150. Const L_Help_HELP_Export02p1_Text = "        /export [/d <DeCryptPass>] /f <File> /sp <SourcePath>"
  151. Const L_Help_HELP_Export02p2_Text = "         [/inherited] [/children]"
  152. Const L_Help_HELP_Export17_Text   = "/inherited              Export inherited settings if set."
  153. Const L_Help_HELP_Export18_Text   = "/children               Export configuration for child nodes."
  154. Const L_Help_HELP_Export22_Text   = "IIsCnfg /export /f c:\config.xml /sp /lm/w3svc/5/Root/401Kapp"
  155.  
  156. ' Save help messages
  157. Const L_Help_HELP_Save01_Text   = "Description:  Save configuration to disk."
  158. Const L_Help_HELP_Save02_Text   = "Syntax: iiscnfg [/s <server> [/u <username> [/p <password>]]]"
  159. Const L_Help_HELP_Save02p2_Text = "                 /save"
  160. Const L_Help_HELP_Save22_Text   = "iiscnfg.vbs /save"
  161. Const L_Help_HELP_Save23_Text   = "iiscnfg.vbs /s SourceServer /u Administrator /p Kj30W /save"
  162.  
  163. ''''''''''''''''''''''''
  164. ' Operation codes
  165. Const OPER_IMPORT = 1
  166. Const OPER_EXPORT = 2
  167. Const OPER_COPY   = 3
  168. Const OPER_SAVE   = 4
  169.  
  170. ' Import/Export flags
  171. Const IMPORT_EXPORT_INHERITED = 1
  172. Const IMPORT_EXPORT_NODE_ONLY = 2
  173. Const IMPORT_EXPORT_MERGE     = 4
  174.  
  175. '
  176. ' Main block
  177. '
  178. Dim oScriptHelper, oCmdLib
  179. Dim strServer, strUser, strPassword, strSite
  180. Dim strTarServer, strTarUser, strTarPassword
  181. Dim strFile, strDecPass, strSourcePath, strDestPath
  182. Dim intOperation, intResult, intFlags
  183. Dim aArgs, arg
  184. Dim strCmdLineOptions
  185. Dim oError
  186.  
  187. ' Default values
  188. strServer = "."
  189. strUser = ""
  190. strPassword = ""
  191. strTarServer = ""
  192. strTarUser = ""
  193. strTarPassword = ""
  194. intOperation = 0
  195. strFile = ""
  196. strDecPass = ""
  197. strSourcePath = ""
  198. strDestPath = ""
  199. intFlags = IMPORT_EXPORT_NODE_ONLY
  200.  
  201. ' Instantiate the CmdLib for output string formatting
  202. Set oCmdLib = CreateObject("Microsoft.CmdLib")
  203. If Err.Number <> 0 Then
  204.     WScript.Echo L_CmdLib_ErrorMessage
  205.     WScript.Echo L_ChkCmdLibReg_ErrorMessage    
  206.     WScript.Quit(ERR_GENERAL_FAILURE)
  207. End If
  208. Set oCmdLib.ScriptingHost = WScript.Application
  209.  
  210. ' Instantiate script helper object
  211. Set oScriptHelper = CreateObject("Microsoft.IIsScriptHelper")
  212. If Err.Number <> 0 Then
  213.     WScript.Echo L_ScriptHelper_ErrorMessage
  214.     WScript.Echo L_ScriptHelperp2_ErrorMessage
  215.     WScript.Echo L_ChkScpHelperReg_ErrorMessage    
  216.     WScript.Echo L_ChkScpHelperRegp2_ErrorMessage    
  217.     WScript.Quit(ERR_GENERAL_FAILURE)
  218. End If
  219.  
  220. Set oScriptHelper.ScriptHost = WScript
  221.  
  222. ' Check if we are being run with cscript.exe instead of wscript.exe
  223. oScriptHelper.CheckScriptEngine
  224.  
  225. ' Minimum number of parameters must exist
  226. If WScript.Arguments.Count < 1 Then
  227.     WScript.Echo L_RequiredArgsMissing_ErrorMessage
  228.     WScript.Echo L_SeeHelp_Message
  229.     WScript.Quit(ERR_GENERAL_FAILURE)
  230. End If
  231.  
  232. strCmdLineOptions = "[server:s:1;user:u:1;password:p:1];decpass:d:1;file:f:1;sourcepath:sp:1;" & _
  233.                     "inherited:i:0;children:c:0;[import::0;destpath:dp:1;merge:m:0];save::0;" & _
  234.                     "export::0;[copy::0;targetserver:ts:1;targetuser:tu:1;targetpassword:tp:1]"
  235. Set oError = oScriptHelper.ParseCmdLineOptions(strCmdLineOptions)
  236.  
  237. If Not oError Is Nothing Then
  238.     If oError.ErrorCode = oScriptHelper.ERROR_NOT_ENOUGH_ARGS Then
  239.         ' Not enough arguments for a specified switch
  240.         WScript.Echo L_NotEnoughParams_ErrorMessage
  241.            WScript.Echo L_SeeHelp_Message
  242.     Else
  243.         ' Invalid switch
  244.         oCmdLib.vbPrintf L_InvalidSwitch_ErrorMessage, Array(oError.SwitchName)
  245.           WScript.Echo L_SeeHelp_Message
  246.     End If
  247.         
  248.         WScript.Quit(ERR_GENERAL_FAILURE)
  249. End If
  250.  
  251. If oScriptHelper.GlobalHelpRequested Then
  252.     DisplayHelpMessage
  253.     WScript.Quit(ERR_OK)
  254. End If
  255.  
  256. For Each arg In oScriptHelper.Switches
  257.     Select Case arg
  258.         Case "server"
  259.             ' Server information
  260.             strServer = oScriptHelper.GetSwitch(arg)
  261.  
  262.         Case "user"
  263.             ' User information
  264.             strUser = oScriptHelper.GetSwitch(arg)
  265.  
  266.         Case "password"
  267.             ' Password information
  268.             strPassword = oScriptHelper.GetSwitch(arg)
  269.             
  270.         Case "targetserver"
  271.             ' Server information
  272.             strTarServer = oScriptHelper.GetSwitch(arg)
  273.  
  274.         Case "targetuser"
  275.             ' User information
  276.             strTarUser = oScriptHelper.GetSwitch(arg)
  277.  
  278.         Case "targetpassword"
  279.             ' Password information
  280.             strTarPassword = oScriptHelper.GetSwitch(arg)
  281.             
  282.         Case "import"
  283.             If (intOperation <> 0) Then
  284.                 WScript.Echo L_OnlyOneOper_ErrorMessage
  285.                 WScript.Echo L_SeeHelp_Message
  286.                 WScript.Quit(ERR_GENERAL_FAILURE)
  287.             End If
  288.  
  289.             intOperation = OPER_IMPORT
  290.  
  291.             If oScriptHelper.IsHelpRequested(arg) Then
  292.                 DisplayImportHelpMessage
  293.                 WScript.Quit(ERR_OK)
  294.             End If
  295.  
  296.         Case "export"
  297.             If (intOperation <> 0) Then
  298.                 WScript.Echo L_OnlyOneOper_ErrorMessage
  299.                 WScript.Echo L_SeeHelp_Message
  300.                 WScript.Quit(ERR_GENERAL_FAILURE)
  301.             End If
  302.  
  303.             intOperation = OPER_EXPORT
  304.  
  305.             If oScriptHelper.IsHelpRequested(arg) Then
  306.                 DisplayExportHelpMessage
  307.                 WScript.Quit(ERR_OK)
  308.             End If
  309.  
  310.         Case "copy"
  311.             If (intOperation <> 0) Then
  312.                 WScript.Echo L_OnlyOneOper_ErrorMessage
  313.                 WScript.Echo L_SeeHelp_Message
  314.                 WScript.Quit(ERR_GENERAL_FAILURE)
  315.             End If
  316.  
  317.             intOperation = OPER_COPY
  318.  
  319.             If oScriptHelper.IsHelpRequested(arg) Then
  320.                 DisplayCopyHelpMessage
  321.                 WScript.Quit(ERR_OK)
  322.             End If
  323.  
  324.         Case "save"
  325.             If (intOperation <> 0) Then
  326.                 WScript.Echo L_OnlyOneOper_ErrorMessage
  327.                 WScript.Echo L_SeeHelp_Message
  328.                 WScript.Quit(ERR_GENERAL_FAILURE)
  329.             End If
  330.  
  331.             intOperation = OPER_SAVE
  332.  
  333.             If oScriptHelper.IsHelpRequested(arg) Then
  334.                 DisplaySaveHelpMessage
  335.                 WScript.Quit(ERR_OK)
  336.             End If
  337.  
  338.         Case "file"
  339.             strFile = oScriptHelper.GetSwitch(arg)
  340.  
  341.         Case "decpass"
  342.             strDecPass = oScriptHelper.GetSwitch(arg)
  343.  
  344.         Case "sourcepath"
  345.             strSourcePath = oScriptHelper.GetSwitch(arg)
  346.  
  347.         Case "destpath"
  348.             strDestPath = oScriptHelper.GetSwitch(arg)
  349.  
  350.         Case "inherited"
  351.             intFlags = intFlags Or IMPORT_EXPORT_INHERITED
  352.             
  353.         Case "children"
  354.             intFlags = intFlags And Not IMPORT_EXPORT_NODE_ONLY
  355.  
  356.         Case "merge"
  357.             intFlags = intFlags Or IMPORT_EXPORT_MERGE
  358.  
  359.     End Select
  360. Next
  361.  
  362. ' Check Parameters
  363. If intOperation = 0 Then
  364.     WScript.Echo L_OperationRequired_ErrorMessage
  365.     WScript.Echo L_SeeHelp_Message
  366.     WScript.Quit(ERR_GENERAL_FAILURE)
  367. End If
  368.  
  369. If intOperation = OPER_SAVE Then
  370. ElseIf intOperation = OPER_COPY Then
  371.     If strTarServer = "" Or strTarUser = "" Or strTarPassword = "" Then
  372.         WScript.Echo L_RequiredArgsMissing_ErrorMessage
  373.         WScript.Quit(ERR_GENERAL_FAILURE)
  374.     End If
  375. Else
  376.     If strFile = "" Or strSourcePath = "" Or (intOperation = OPER_IMPORT And strDestPath = "") Then
  377.         WScript.Echo L_RequiredArgsMissing_ErrorMessage
  378.         If intOperation = OPER_IMPORT Then
  379.             WScript.Echo L_SeeImportHelp_Message
  380.         Else
  381.             WScript.Echo L_SeeExportHelp_Message
  382.         End If
  383.         WScript.Quit(ERR_GENERAL_FAILURE)
  384.     End If
  385. End If
  386.  
  387. ' Check if /p is specified but /u isn't. In this case, we should bail out with an error
  388. If oScriptHelper.Switches.Exists("password") And Not oScriptHelper.Switches.Exists("user") Then
  389.     WScript.Echo L_PassWithoutUser_ErrorMessage
  390.     WScript.Quit(ERR_GENERAL_FAILURE)
  391. End If
  392.  
  393. ' Check if /u is specified but /p isn't. In this case, we should ask for a password
  394. If oScriptHelper.Switches.Exists("user") And Not oScriptHelper.Switches.Exists("password") Then
  395.     strPassword = oCmdLib.GetPassword
  396. End If
  397.  
  398. ' Initializes authentication with remote machine
  399. intResult = oScriptHelper.InitAuthentication(strServer, strUser, strPassword)
  400. If intResult <> 0 Then
  401.     WScript.Quit(intResult)
  402. End If
  403.  
  404. ' Choose operation
  405. Select Case intOperation
  406.     Case OPER_IMPORT
  407.         intResult = Import(strDecPass, strFile, strSourcePath, strDestPath, intFlags)
  408.         
  409.     Case OPER_EXPORT
  410.         intResult = Export(strDecPass, strFile, strSourcePath, intFlags)
  411.  
  412.     Case OPER_COPY
  413.         intResult = Repl(strServer, strUser, strPassword, strTarServer, strTarUser, strTarPassword)
  414.  
  415.     Case OPER_SAVE
  416.         intResult = SaveMD()
  417.  
  418. End Select
  419.  
  420. ' Return value to command processor
  421. WScript.Quit(intResult)
  422.  
  423. '''''''''''''''''''''''''
  424. ' End Of Main Block
  425. '''''''''''''''''''''
  426.  
  427. '''''''''''''''''''''''''''
  428. ' DisplayHelpMessage
  429. '''''''''''''''''''''''''''
  430. Sub DisplayHelpMessage()
  431.     WScript.Echo L_Help_HELP_General01_Text
  432.     WScript.Echo L_Empty_Text
  433.     WScript.Echo L_Help_HELP_General02_Text
  434.     WScript.Echo L_Help_HELP_General03_Text
  435.     WScript.Echo L_Empty_Text
  436.     WScript.Echo L_Help_HELP_General04_Text
  437.     WScript.Echo L_Help_HELP_General05_Text
  438.     WScript.Echo L_Help_HELP_General06_Text
  439.     WScript.Echo L_Help_HELP_General07_Text
  440.     WScript.Echo L_Help_HELP_General07p2_Text
  441.     WScript.Echo L_Help_HELP_General08_Text
  442.     WScript.Echo L_Help_HELP_General09_Text
  443.     WScript.Echo L_Help_HELP_General10_Text
  444.     WScript.Echo L_Help_HELP_General11_Text
  445.     WScript.Echo L_Help_HELP_General11p1_Text
  446.     WScript.Echo L_Help_HELP_General12_Text
  447.     WScript.Echo L_Help_HELP_General12p1_Text
  448.     WScript.Echo L_Help_HELP_General13_Text
  449.     WScript.Echo L_Help_HELP_General14_Text
  450.     WScript.Echo L_Empty_Text
  451.     WScript.Echo L_Help_HELP_General22_Text
  452.     WScript.Echo L_Empty_Text
  453.     WScript.Echo L_Help_HELP_General23_Text
  454.     WScript.Echo L_Help_HELP_General24_Text
  455.     WScript.Echo L_Help_HELP_General25_Text
  456.     WScript.Echo L_Help_HELP_General26_Text
  457. End Sub
  458.  
  459. Sub DisplayImportHelpMessage()
  460.     WScript.Echo L_Help_HELP_Import01_Text
  461.     WScript.Echo L_Empty_Text
  462.     WScript.Echo L_Help_HELP_Import02_Text
  463.     WScript.Echo L_Help_HELP_Import02p1_Text
  464.     WScript.Echo L_Help_HELP_Import02p2_Text
  465.     WScript.Echo L_Empty_Text
  466.     WScript.Echo L_Help_HELP_General06_Text
  467.     WScript.Echo L_Help_HELP_General07_Text
  468.     WScript.Echo L_Help_HELP_General07p2_Text
  469.     WScript.Echo L_Help_HELP_General08_Text
  470.     WScript.Echo L_Help_HELP_General09_Text
  471.     WScript.Echo L_Help_HELP_General10_Text
  472.     WScript.Echo L_Help_HELP_Common13_Text
  473.     WScript.Echo L_Help_HELP_Common13p1_Text
  474.     WScript.Echo L_Help_HELP_Common13p2_Text
  475.     WScript.Echo L_Help_HELP_Common14_Text
  476.     WScript.Echo L_Help_HELP_Common15_Text
  477.     WScript.Echo L_Help_HELP_Common15p1_Text
  478.     WScript.Echo L_Help_HELP_Import16_Text
  479.     WScript.Echo L_Help_HELP_Import16p1_Text
  480.     WScript.Echo L_Help_HELP_Import16p2_Text
  481.     WScript.Echo L_Help_HELP_Import16p3_Text
  482.     WScript.Echo L_Help_HELP_Import17_Text
  483.     WScript.Echo L_Help_HELP_Import18_Text
  484.     WScript.Echo L_Help_HELP_Import19_Text
  485.     WScript.Echo L_Help_HELP_Import19p1_Text
  486.     WScript.Echo L_Empty_Text
  487.     WScript.Echo L_Help_HELP_Common21_Text
  488.     WScript.Echo L_Empty_Text
  489.     WScript.Echo L_Help_HELP_Import22_Text
  490.     WScript.Echo L_Help_HELP_Import22p1_Text
  491. End Sub
  492.  
  493. Sub DisplayCopyHelpMessage()
  494.     WScript.Echo L_Help_HELP_Copy1_Text
  495.     WScript.Echo L_Help_HELP_Copy1p2_Text
  496.     WScript.Echo L_Empty_Text
  497.     WScript.Echo L_Help_HELP_Copy2_Text
  498.     WScript.Echo L_Help_HELP_Copy2p2_Text
  499.     WScript.Echo L_Help_HELP_Copy2p3_Text
  500.     WScript.Echo L_Help_HELP_Copy3_Text
  501.     WScript.Echo L_Empty_Text
  502.     WScript.Echo L_Help_HELP_Copy4_Text
  503.     WScript.Echo L_Help_HELP_Copy5_Text
  504.     WScript.Echo L_Help_HELP_Copy5p2_Text
  505.     WScript.Echo L_Help_HELP_Copy6_Text
  506.     WScript.Echo L_Help_HELP_Copy7_Text
  507.     WScript.Echo L_Help_HELP_Copy8_Text
  508.     WScript.Echo L_Help_HELP_Copy9_Text
  509.     WScript.Echo L_Help_HELP_Copy10_Text
  510.     WScript.Echo L_Help_HELP_Copy10p2_Text
  511.     WScript.Echo L_Help_HELP_Copy11_Text
  512.     WScript.Echo L_Help_HELP_Copy11p2_Text
  513.     WScript.Echo L_Empty_Text
  514.     WScript.Echo L_Help_HELP_Copy12_Text
  515.     WScript.Echo L_Empty_Text
  516.     WScript.Echo L_Help_HELP_Copy13_Text
  517.     WScript.Echo L_Help_HELP_Copy14_Text
  518.     WScript.Echo L_Help_HELP_Copy14p2_Text
  519. End Sub
  520.  
  521. Sub DisplayExportHelpMessage()
  522.     WScript.Echo L_Help_HELP_Export01_Text
  523.     WScript.Echo L_Empty_Text
  524.     WScript.Echo L_Help_HELP_Export02_Text
  525.     WScript.Echo L_Help_HELP_Export02p1_Text
  526.     WScript.Echo L_Help_HELP_Export02p2_Text
  527.     WScript.Echo L_Empty_Text
  528.     WScript.Echo L_Help_HELP_General06_Text
  529.     WScript.Echo L_Help_HELP_General07_Text
  530.     WScript.Echo L_Help_HELP_General07p2_Text
  531.     WScript.Echo L_Help_HELP_General08_Text
  532.     WScript.Echo L_Help_HELP_General09_Text
  533.     WScript.Echo L_Help_HELP_General10_Text
  534.     WScript.Echo L_Help_HELP_Common13_Text
  535.     WScript.Echo L_Help_HELP_Common13p1_Text
  536.     WScript.Echo L_Help_HELP_Common13p2_Text
  537.     WScript.Echo L_Help_HELP_Common14_Text
  538.     WScript.Echo L_Help_HELP_Common15_Text
  539.     WScript.Echo L_Help_HELP_Common15p1_Text
  540.     WScript.Echo L_Help_HELP_Export17_Text
  541.     WScript.Echo L_Help_HELP_Export18_Text
  542.     WScript.Echo L_Empty_Text
  543.     WScript.Echo L_Help_HELP_Common21_Text
  544.     WScript.Echo L_Empty_Text
  545.     WScript.Echo L_Help_HELP_Export22_Text
  546. End Sub
  547.  
  548. Sub DisplaySaveHelpMessage()
  549.     WScript.Echo L_Help_HELP_Save01_Text
  550.     WScript.Echo L_Empty_Text
  551.     WScript.Echo L_Help_HELP_Save02_Text
  552.     WScript.Echo L_Help_HELP_Save02p2_Text
  553.     WScript.Echo L_Empty_Text
  554.     WScript.Echo L_Help_HELP_General06_Text
  555.     WScript.Echo L_Help_HELP_General07_Text
  556.     WScript.Echo L_Help_HELP_General07p2_Text
  557.     WScript.Echo L_Help_HELP_General08_Text
  558.     WScript.Echo L_Help_HELP_General09_Text
  559.     WScript.Echo L_Help_HELP_General10_Text
  560.     WScript.Echo L_Empty_Text
  561.     WScript.Echo L_Help_HELP_Common21_Text
  562.     WScript.Echo L_Empty_Text
  563.     WScript.Echo L_Help_HELP_Save22_Text
  564.     WScript.Echo L_Help_HELP_Save23_Text
  565. End Sub
  566.  
  567. '''''''''''''''''''''''''''
  568. ' Copy Function
  569. '''''''''''''''''''''''''''
  570. Function Repl(strSourceServer, strSourceUser, strSourcePwd, strDestServer, strDestUser, strDestPwd)
  571.  
  572.     If (strSourceServer = ".") Then
  573.         strSourceServer = ""
  574.     End If
  575.  
  576.     ' Do the first backup
  577.  
  578.     Dim strBackupCommand
  579.     Dim strSourceDrive, strDrvLetter, strSourcePath
  580.     Dim oShell, oFS, oNetwork
  581.     Dim strDestDrive, strDestPath
  582.     Dim strCopyCommand, strDelCommand, strRestoreCommand
  583.  
  584.     Set oShell = WScript.CreateObject("WScript.Shell")
  585.     If Err.Number <> 0 Then
  586.         WScript.Echo L_Shell_ErrorMessage
  587.         WScript.Echo L_Shellp2_ErrorMessage
  588.         WScript.Quit(ERR_GENERAL_FAILURE)
  589.     End If
  590.  
  591.     Set oFS = WScript.CreateObject("Scripting.FileSystemObject")
  592.     If Err.Number <> 0 Then
  593.         WScript.Echo L_FS_ErrorMessage
  594.         WScript.Echo L_FSp2_ErrorMessage
  595.         WScript.Quit(ERR_GENERAL_FAILURE)
  596.     End If
  597.  
  598.     Set oNetwork = WScript.CreateObject("WScript.Network")
  599.     If Err.Number <> 0 Then
  600.         WScript.Echo L_Network_ErrorMessage
  601.         WScript.Echo L_Networkp2_ErrorMessage
  602.         WScript.Quit(ERR_GENERAL_FAILURE)
  603.     End If
  604.  
  605.     strBackupCommand =  "cmd /c %SystemRoot%\system32\cscript.exe %SystemRoot%\system32\iisback.vbs /backup"
  606.  
  607.     If strSourceServer <> "" Then
  608.         strBackupCommand = strBackupCommand & " /s " & strSourceServer 
  609.     Else
  610.         strSourceServer = "127.0.0.1"
  611.     End If
  612.  
  613.     If strSourceUser <> "" Then
  614.         strBackupCommand = strBackupCommand & " /u " & strSourceUser
  615.     End If
  616.  
  617.     If strSourcePwd <> "" Then
  618.         strBackupCommand = strBackupCommand & " /p " & strSourcePwd
  619.     End If
  620.  
  621.     ' need overwrite in case a previous attempt failed
  622.     strBackupCommand = strBackupCommand & " /b iisreplback /overwrite"
  623.  
  624.     ' backup the source server
  625.     oCmdLib.vbPrintf L_BackingUp_Message, Array(strSourceServer)
  626.     intResult = oShell.Run(strBackupCommand, 1, TRUE)
  627.  
  628.     WScript.Echo L_BackupComplete_Message
  629.  
  630.     ' Now map drive to source server
  631.     ' Find a drive letter
  632.  
  633.     strSourceDrive = "NO DRIVE"
  634.     For strDrvLetter = Asc("C") to Asc("Z")
  635.         If Not oFS.DriveExists(Chr(strDrvLetter)) Then
  636.             strSourceDrive = Chr(strDrvLetter)
  637.             Exit For
  638.         End If
  639.     Next
  640.  
  641.     If strSourceDrive = "NO DRIVE" Then
  642.         ' No drive letter available
  643.         WScript.Echo L_NoDrive_ErrorMessage
  644.         WScript.Quit(ERR_GENERAL_FAILURE)
  645.     End If
  646.  
  647.     strSourceDrive = strSourceDrive & ":"
  648.     strSourcePath = "\\" & strSourceServer & "\ADMIN$"
  649.  
  650.     ' Map the drive
  651.     oCmdLib.vbPrintf L_DriveLetter_Message, Array(strSourceDrive, strSourceServer)
  652.  
  653.     If strSourceUser <> "" Then
  654.         oNetwork.MapNetworkDrive strSourceDrive, strSourcePath, FALSE, strSourceUser, strSourcePwd
  655.     Else
  656.         oNetwork.MapNetworkDrive strSourceDrive, strSourcePath
  657.     End If
  658.  
  659.     ' Now map drive to destination server
  660.     ' Find a drive letter
  661.  
  662.     strDestDrive = "NO DRIVE"
  663.     For strDrvLetter = Asc("C") to Asc("Z")
  664.         If Not oFS.DriveExists(Chr(strDrvLetter)) Then
  665.             strDestDrive = Chr(strDrvLetter)
  666.             Exit For
  667.         End If
  668.     Next
  669.  
  670.     If strDestDrive = "NO DRIVE" Then
  671.         ' No drive letter available
  672.         WScript.Echo L_NoDrive_ErrorMessage
  673.         WScript.Quit(ERR_GENERAL_FAILURE)
  674.     End If
  675.  
  676.     strDestDrive = strDestDrive & ":"
  677.     strDestPath = "\\" & strDestServer & "\ADMIN$"
  678.  
  679.     ' Map the drive
  680.     oCmdLib.vbPrintf L_DriveLetter_Message, Array(strDestDrive, strDestServer)
  681.  
  682.     If strDestUser <> "" Then
  683.         oNetwork.MapNetworkDrive strDestDrive, strDestPath, FALSE, strDestUser, strDestPwd
  684.     Else
  685.         oNetwork.MapNetworkDrive strDestDrive, strDestPath
  686.     End If
  687.  
  688.     strCopyCommand = "cmd /c copy /Y " & strSourceDrive & "\system32\inetsrv\metaback\iisreplback.* "
  689.     strCopyCommand = strCopyCommand & strDestDrive & "\system32\inetsrv\metaback"
  690.  
  691.     ' Copy the files
  692.     WScript.Echo L_Copy_Message
  693.     WScript.Echo strCopyCommand
  694.     intResult = oShell.Run(strCopyCommand, 1, TRUE)
  695.       
  696.     If intResult <> 0 Then
  697.         oCmdLib.vbPrintf L_ReturnVal_ErrorMessage, Array(intResult)
  698.         WScript.Echo L_Copy_ErrorMessage
  699.         WScript.Quit(intResult)
  700.     End If 
  701.  
  702.     strDelCommand = "cmd /c del /f /q " & strSourceDrive & "\system32\inetsrv\metaback\iisreplback.*"
  703.     intResult = oShell.Run(strDelCommand, 1, TRUE)
  704.  
  705.     ' Unmap drive to source server
  706.     oCmdLib.vbPrintf L_UnMap_Message, Array(strSourceDrive)
  707.     oNetwork.RemoveNetworkDrive strSourceDrive
  708.  
  709.     ' Now do the restore on the destination server
  710.  
  711.     strRestoreCommand = "cmd /c %SystemRoot%\system32\cscript.exe %SystemRoot%\system32\iisback.vbs /restore /s " & strDestServer
  712.     strRestoreCommand = strRestoreCommand & " /u " & strDestUser
  713.     strRestoreCommand = strRestoreCommand & " /p " & strDestPwd
  714.     strRestoreCommand = strRestoreCommand & " /b iisreplback"
  715.  
  716.     oCmdLib.vbPrintf L_Restoring_Message, Array(strDestServer)
  717.     intResult = oShell.Run(strRestoreCommand, 1, TRUE)
  718.  
  719.     If intResult <> 0 Then
  720.         oCmdLib.vbPrintf L_ReturnVal_ErrorMessage, Array(intResult)
  721.         WScript.Echo L_Restore_ErrorMessage
  722.         WScript.Quit(intResult)
  723.     End If 
  724.  
  725.     WScript.Echo L_RestoreComplete_Message
  726.  
  727.     strDelCommand = "cmd /c del /f /q " & strDestDrive & "\system32\inetsrv\metaback\iisreplback.*"
  728.     intResult = oShell.Run(strDelCommand, 1, TRUE)
  729.  
  730.     ' Unmap drive to destination server
  731.     oCmdLib.vbPrintf L_UnMap_Message, Array(strDestDrive)
  732.     oNetwork.RemoveNetworkDrive strDestDrive
  733.  
  734.     WScript.Echo L_CopyComplete_Message
  735. End Function
  736.  
  737. '''''''''''''''''''''''''''
  738. ' Import Function
  739. '''''''''''''''''''''''''''
  740. Function Import(strDecPass, strFile, strSourcePath, strDestPath, intFlags)
  741.     Dim ComputerObj
  742.     Dim strFilePath
  743.     
  744.     On Error Resume Next
  745.  
  746.     ' Normalize path first
  747.     strFilePath = oScriptHelper.NormalizeFilePath(strFile)
  748.     If Err Then
  749.         Select Case Err.Number
  750.             Case &H80070002
  751.                 WScript.Echo L_FileExpected_ErrorMessage
  752.                 WScript.Echo L_FileExpectedp2_ErrorMessage
  753.  
  754.             Case &H80070003
  755.                 WScript.Echo L_ParentFolderDoesntExist_ErrorMessage
  756.         End Select
  757.         
  758.         Import = Err.Number
  759.         Exit Function
  760.     End If
  761.  
  762.     oScriptHelper.WMIConnect
  763.     If Err.Number Then
  764.         WScript.Echo L_WMIConnect_ErrorMessage
  765.         oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  766.         Import = Err.Number
  767.         Exit Function
  768.     End If
  769.  
  770.     Set ComputerObj = oScriptHelper.ProviderObj.get("IIsComputer='LM'")
  771.     If Err.Number Then
  772.         Select Case Err.Number
  773.             Case &H80070005
  774.                 WScript.Echo L_Admin_ErrorMessage
  775.                 WScript.Echo L_Adminp2_ErrorMessage
  776.  
  777.             Case Else
  778.                 WScript.Echo L_GetComputerObj_ErrorMessage
  779.                 oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  780.         End Select
  781.  
  782.         Import = Err.Number
  783.         Exit Function
  784.     End If
  785.     
  786.     ' Call Import method from the computer object
  787.     ComputerObj.Import strDecPass, strFilePath, strSourcePath, strDestPath, intFlags
  788.     If Err.Number Then
  789.         Select Case Err.Number
  790.             Case &H80070002
  791.                 WScript.Echo L_FileDoesntExist_ErrorMessage
  792.  
  793.             Case &H8007052B
  794.                 WScript.Echo L_IncorrectPassword_ErrorMessage
  795.  
  796.             Case &H800CC819
  797.                 WScript.Echo L_InvalidXML_ErrorMessage
  798.  
  799.             Case Else
  800.                 WScript.Echo L_Import_ErrorMessage
  801.                 WScript.Echo Err.Description
  802.         End Select
  803.         
  804.         Import = Err.Number
  805.         Exit Function
  806.     End If
  807.     
  808.     oCmdLib.vbPrintf L_ConfImported_Text, Array(strSourcePath)
  809.     oCmdLib.vbPrintf L_ConfImportedp2_Text, Array(strFile, strDestPath)
  810. End Function
  811.  
  812. '''''''''''''''''''''''''''
  813. ' Export Function
  814. '''''''''''''''''''''''''''
  815. Function Export(strDecPass, strFile, strSourcePath, intFlags)
  816.     Dim ComputerObj
  817.     Dim strFilePath
  818.     
  819.     On Error Resume Next
  820.  
  821.     ' Normalize path first
  822.     strFilePath = oScriptHelper.NormalizeFilePath(strFile)
  823.     If Err Then
  824.         Select Case Err.Number
  825.             Case &H80070002
  826.                 WScript.Echo L_FileExpected_ErrorMessage
  827.                 WScript.Echo L_FileExpectedp2_ErrorMessage
  828.  
  829.             Case &H80070003
  830.                 WScript.Echo L_ParentFolderDoesntExist_ErrorMessage
  831.         End Select
  832.         
  833.         Export = Err.Number
  834.         Exit Function
  835.     End If
  836.  
  837.     If oScriptHelper.FSObj.FileExists(strFilePath) Then
  838.         WScript.Echo L_FileAlreadyExist_ErrorMessage
  839.         Export = &H80070050
  840.         Exit Function
  841.     End If
  842.  
  843.     oScriptHelper.WMIConnect
  844.     If Err.Number Then
  845.         WScript.Echo L_WMIConnect_ErrorMessage
  846.         oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  847.         Export = Err.Number
  848.         Exit Function
  849.     End If
  850.  
  851.     Set ComputerObj = oScriptHelper.ProviderObj.get("IIsComputer='LM'")
  852.     If Err.Number Then
  853.         Select Case Err.Number
  854.             Case &H80070005
  855.                 WScript.Echo L_Admin_ErrorMessage
  856.                 WScript.Echo L_Adminp2_ErrorMessage
  857.  
  858.             Case Else
  859.                 WScript.Echo L_GetComputerObj_ErrorMessage
  860.                 oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  861.         End Select
  862.  
  863.         Export = Err.Number
  864.         Exit Function
  865.     End If
  866.     
  867.     ' Call Import method from the computer object
  868.     ComputerObj.Export strDecPass, strFilePath, strSourcePath, intFlags
  869.     If Err.Number Then
  870.         WScript.Echo L_Export_ErrorMessage
  871.         WScript.Echo Err.Description
  872.         Export = Err.Number
  873.         Exit Function
  874.     End If
  875.  
  876.     oCmdLib.vbPrintf L_ConfExported_Text, Array(strSourcePath, strFile)    
  877. End Function
  878.  
  879. '''''''''''''''''''''''''''
  880. ' SaveMD Function
  881. '''''''''''''''''''''''''''
  882. Function SaveMD()
  883.     Dim ComputerObj
  884.     
  885.     On Error Resume Next
  886.  
  887.     oScriptHelper.WMIConnect
  888.     If Err.Number Then
  889.         WScript.Echo L_WMIConnect_ErrorMessage
  890.         oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  891.         SaveMD = Err.Number
  892.         Exit Function
  893.     End If
  894.  
  895.     Set ComputerObj = oScriptHelper.ProviderObj.get("IIsComputer='LM'")
  896.     If Err.Number Then
  897.         Select Case Err.Number
  898.             Case &H80070005
  899.                 WScript.Echo L_Admin_ErrorMessage
  900.                 WScript.Echo L_Adminp2_ErrorMessage
  901.  
  902.             Case Else
  903.                 WScript.Echo L_GetComputerObj_ErrorMessage
  904.                 oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  905.         End Select
  906.  
  907.         SaveMD = Err.Number
  908.         Exit Function
  909.     End If
  910.     
  911.     ' Call Import method from the computer object
  912.     ComputerObj.SaveData
  913.     If Err.Number Then
  914.         WScript.Echo L_SaveData_ErrorMessage
  915.         WScript.Echo Err.Description
  916.         SaveMD = Err.Number
  917.         Exit Function
  918.     End If
  919.  
  920.     WScript.Echo L_MDSaved_Text    
  921. End Function
  922.